<template>
  <base-page-view class-name="page-container app-pay-container">
  </base-page-view>
</template>
<script>
import { toPay } from '@/utils/tools'
import './index.scss'
export default {
  name: 'AppPay',
  data() {
    return {
      order_no: ''
    }
  },
  onLoad(option) {
    this.order_no = option.order_no
  },
  methods: {
    app_interactive_data() {
      uni.login({
        provider: 'weixin',
        success: async(res) => {
          if (res.errMsg === 'login:ok') {
            const result = await this.$api.orderApi.orderPay({
              pay_channel: 6, // type,
              order_no: this.order_no,
              // ip: window.returnCitySN ? window.returnCitySN.cip : ''
              ip: '0.0.0.0',
              code: res.code
            })
            if (result.success) {
              toPay({
                ...result.data,
                success: (res1) => {
                  this.$navigateTo(`/pagesOrder/orderDetail/index?orderNo=${this.order_no}`, {}, 'reLaunch')
                },
                fail: () => {
                  this.$navigateTo(`/pagesOrder/orderDetail/index?orderNo=${this.order_no}`, {}, 'reLaunch')
                }
              })
            }
          }
        },
        fail: (err) => {
          uni.showToast({
            title: err.errMsg || '登录获取code失败',
            icon: 'none',
            duration: 3 * 1000
          })
        }
      })
    }
  }
}
</script>
